<?php

namespace app\admin\model\project;

use think\Model;
use traits\model\SoftDelete;

class Project extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'project';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'mold_text',
        'index_text',
        'recommend_text',
        'status_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getMoldList()
    {
        return ['mini' => __('Mold mini'), 'app' => __('Mold app'), 'pc' => __('Mold pc')];
    }

    public function getIndexList()
    {
        return ['0' => __('Index 0'), '1' => __('Index 1')];
    }

    public function getRecommendList()
    {
        return ['0' => __('Recommend 0'), '1' => __('Recommend 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getMoldTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['mold']) ? $data['mold'] : '');
        $list = $this->getMoldList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIndexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['index']) ? $data['index'] : '');
        $list = $this->getIndexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRecommendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['recommend']) ? $data['recommend'] : '');
        $list = $this->getRecommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function category(){
        return $this->belongsTo('app\admin\model\project\Category','cate_id','id');
    }

}
